package com.landinfo.domain;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.hibernate.annotations.GenericGenerator;
import javax.persistence.*;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.util.LinkedHashSet;
import java.util.Objects;
import java.util.Set;

/**
 * 数据字典
 * Create by lzq
 * 2017-06-06
 */
@ApiModel(description = "数据字典 Create by lzq 2017-06-06")
@Entity
@Table(name = "data_type")
public class DataType2 implements Serializable {

    private static final long serialVersionUID = 1L;


    //    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
//    @SequenceGenerator(name = "sequenceGenerator")
    @Id
    @Column(name = "id", length = 36)
    @GeneratedValue(generator = "system-uuid")
    @GenericGenerator(name = "system-uuid", strategy = "uuid2")
    private String id;


    /**
     * 名称
     */
    @ApiModelProperty(value = "名称")
    @Column(name = "name")
    private String name;

    /**
     * 值
     */
    @ApiModelProperty(value = "值")
    @Column(name = "code")
    private String code;

    /**
     * 排序
     */
    @ApiModelProperty(value = "排序")
    @Column(name = "sorting")
    private Integer sorting;

    /**
     * 备注
     */
    @ApiModelProperty(value = "备注")
    @Column(name = "remark")
    private String remark;

    //    /**
//     * 父级ID
//     */
    @Size(max = 36)
    @ApiModelProperty(value = "父级ID")
    @Column(name = "parent_id", length = 36)
//    private String parentId;
    private String parentId;

    //    @Where(clause = "state=1")
    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    @JoinColumn(name = "parent_id")
    @OrderBy(value = "sorting")
    private Set<DataType2> children = new LinkedHashSet<DataType2>();


    @OneToMany(fetch = FetchType.EAGER,cascade = CascadeType.ALL)
    @JoinColumns(value={@JoinColumn(name="parent_id",referencedColumnName="id")})   //对应关系 Pid = id
    private Set<GpsLocation> gpsLocations = new LinkedHashSet<GpsLocation>();


    public Set<GpsLocation> getGpsLocations() {
        return this.gpsLocations;
    }

    public void setGpsLocations(Set<GpsLocation> gpsLocations) {
        this.gpsLocations = gpsLocations;
    }


    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

//    public String getParentId() {
//        return parentId;
//    }
//
//    public DataType parentId(String parentId) {
//        this.parentId = parentId;
//        return this;
//    }
//
//    public void setParentId(String parentId) {
//        this.parentId = parentId;
//    }

    public String getName() {
        return name;
    }

    public DataType2 name(String name) {
        this.name = name;
        return this;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getCode() {
        return code;
    }

    public DataType2 code(String code) {
        this.code = code;
        return this;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public Integer getSorting() {
        return sorting;
    }

    public DataType2 sorting(Integer sorting) {
        this.sorting = sorting;
        return this;
    }

    public void setSorting(Integer sorting) {
        this.sorting = sorting;
    }

    public String getRemark() {
        return remark;
    }

    public DataType2 remark(String remark) {
        this.remark = remark;
        return this;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }


    public Set<DataType2> getChildren() {
        return this.children;
    }

    public void setChildren(Set<DataType2> children) {
        this.children = children;
    }


    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        DataType2 dataType = (DataType2) o;
        if (dataType.getId() == null || getId() == null) {
            return false;
        }
        return Objects.equals(getId(), dataType.getId());
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(getId());
    }

    @Override
    public String toString() {
        return "DataType{" +
                "id=" + getId() +
                ", parentId='" + getParentId() + "'" +
                ", name='" + getName() + "'" +
                ", code='" + getCode() + "'" +
                ", sorting='" + getSorting() + "'" +
                ", remark='" + getRemark() + "'" +
                "}";
    }

    public String getParentId() {
        return parentId;
    }

    public void setParentId(String parentId) {
        this.parentId = parentId;
    }
}
